package com.alex.service;

import com.alex.dao.OfflineMessage;
import com.alex.dao.OfflineMessageRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * @author shufei
 */
@Service
public class TransactionalServiceImpl implements TransactionalService {

    @Autowired
    private OfflineMessageRepository messageRepository;


    @Override
    public void insertAndFind() {
        OfflineMessage message = new OfflineMessage();
        message.setMessage("insertAndFind");
        message.setStatus(1);
        message.setUserId("TT");

        messageRepository.save(message);

        find(message.getId());
    }

    public void find(Long id) {
        Optional<OfflineMessage> resultById = messageRepository.findById(id);
        System.out.println(resultById.get());
    }
}
